package com.latinia.limsp.test;

import electric.xml.Document;
import electric.xml.Element;
import electric.xml.Elements;
import electric.xml.XPath;

public class TransactionXML {

	String xmltransaction;
	private String transactionType;
	private String messageId;
	private String idclause;
	private String idProduct;
	private String refProduct;
	private String idAddressTo;
	private String to;
	private String idAddressFrom;
	private String from;
	private String idMSGOut;
	private String idTransaction;
	public TransactionXML(String text){
		try {
			Document doc = new Document(text);
			Element element = doc.getElement(new XPath(
					"/transaction/body/message"));
			String idMsg = element.getAttribute("id");
			element = doc.getElement(new XPath("/transaction"));
			idTransaction=element.getAttribute("id");
			idMSGOut=idMsg;
			transactionType = doc.getElement(
					new XPath("/transaction/body/message/head/type"))
					.getAttribute("ref");
			messageId = doc.getElement(new XPath("/transaction/body/message"))
					.getAttribute("id");
			idclause = doc.getElement(
					new XPath("/transaction/head/info/idClause"))
					.getTextString();

			idProduct = doc.getElement(
					new XPath("/transaction/head/info/idProduct"))
					.getTextString();
			refProduct = doc.getElement(
					new XPath("/transaction/head/info/refProduct"))
					.getTextString();
			Elements addressList = doc.getElement(
					new XPath("/transaction/body/message/head/address-list"))
					.getElements();
			while (addressList.hasMoreElements()) {
				Element e = (Element) addressList.nextElement();
				if (e.getAttribute("type").equalsIgnoreCase("to")) {
					idAddressTo = e.getAttribute("id");
					to = e.getAttribute("ref");
				} else if (e.getAttribute("type").equalsIgnoreCase("from")) {
					idAddressFrom = e.getAttribute("id");
					from = e.getAttribute("ref");
				}
			}
		} catch (Exception e) {
			SDPLog.outErr(e);
		}
	}

	public String getIdMSGOut(){
		return idMSGOut;
	}
	public String getIdTransaction(){
		return idTransaction;
	}
	
	public String getTransactionType(){
		return transactionType;
	}
	
	public String getMessageId(){
		return messageId;
	}
	
	public String getIdclause(){
		return idclause;
	}
	
	public String getIdAddressTo() {		
		return idAddressTo;
	}

	public String getTo() {
		return to;
	}

	public String getIdProduct() {
		return idProduct;
	}

	public String getRefProduct() {		
		return refProduct;
	}

	public String getIdAddressFrom() {
		return idAddressFrom;
	}

	public String getFrom() {
		return from;
	}

}
